package com.tarena.csmall.starter.test;

import com.tarena.csmall.starter.test.beans.Bean05;
import com.tarena.csmall.starter.test.configs.MyConfiguration01;
import org.junit.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.support.SpringFactoriesLoader;

import java.util.List;

/**
 * @author java@tedu.cn
 * @version 1.0
 */
public class ApplicationLoadTestRun {
    /**
     * 测试代码
     * 读取xml 加载spring上下文对象
     * 如果spring上下文创建没问题,spring应用启动成功的
     */
    @Test
    public void loadXML(){
        //准备加载的文件路径
        String filePath="classpath:demo01.xml";
        //对应加载spring应用的上下文类型
        ClassPathXmlApplicationContext
                application=new ClassPathXmlApplicationContext(filePath);
    }
    /**
     * 通过配置类加载spring应用
     */
    @Test
    public void loadConfig(){
        //对应加载spring应用的上下文类型
        AnnotationConfigApplicationContext
        application= new AnnotationConfigApplicationContext
                (MyConfiguration01.class);
        Bean05 bean = application.getBean(Bean05.class);
        System.out.println(bean);
    }
    @Test
    public void getFactories(){
        List<String> strings = SpringFactoriesLoader
                .loadFactoryNames(ApplicationListener.class, this.getClass().getClassLoader());
        System.out.println(strings);
        System.out.println(strings.size());
    }
}
